import { defHttp } from '/@/utils/http/axios';
import { SkuModel, SkuListModel, GetSkuListResponseModel } from './model/skuModel';

// 定义请求地址的枚举
enum Api {
  SaveSku = '/admin/product/saveSkuInfo',
  FindSkuListBySpuId = '/admin/product/findBySpuId',
  GetSkuList = '/admin/product/list',
  OnSale = '/admin/product/onSale',
  CancelSale = '/admin/product/cancelSale',
}

/**
 * 添加SKU
 * @param sku
 * @returns
 */
export const saveSkuApi = (sku: SkuModel) => {
  return defHttp.post<null>({
    url: Api.SaveSku,
    data: sku,
  });
};

/**
 * 根据spuId找sku列表
 * @param sku
 * @returns
 */
export const findSkuListBySpuIdApi = (spuId: number) => {
  return defHttp.get<SkuListModel>({
    url: Api.FindSkuListBySpuId,
    params: `/${spuId}`,
  });
};

/**
 * 获取sku分页列表
 * @param page
 * @param limit
 * @returns
 */
export const getSkuListApi = (page: number, limit: number) => {
  return defHttp.get<GetSkuListResponseModel>({
    url: Api.GetSkuList,
    params: `/${page}/${limit}`,
  });
};

/**
 * 上架
 * @param skuId
 * @returns
 */
export const onSaleApi = (skuId: number) => {
  return defHttp.get<null>({
    url: Api.OnSale,
    params: `/${skuId}`,
  });
};

/**
 * 下架
 * @param skuId
 * @returns
 */
export const cancelSaleApi = (skuId: number) => {
  return defHttp.get<null>({
    url: Api.CancelSale,
    params: `/${skuId}`,
  });
};
